<!DOCTYPE html>
<body>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>乐优商城--我的订单</title>
    <link rel="icon" href="assets/img/favicon.ico">

    <link rel="stylesheet" type="text/css" href="css/webbase.css"/>
    <link rel="stylesheet" type="text/css" href="css/pages-seckillOrder.css"/>
</head>

<!-- 头部栏位 -->
<!--页面顶部，由js动态加载-->
<script type="text/javascript" src="plugins/jquery/jquery.min.js"></script>
<div id="nav-bottom">
    <ly-top></ly-top>
</div>
<script src="./js/vue/vue.js"></script>
<script type="text/javascript">
    //$("#nav-bottom").load("top.html");
    var indexVm = new Vue({
        el: "#nav-bottom",
        components: {
            lyTop: () => import('./js/pages/top.js')
        }
    });
</script>

<script type="text/javascript" src="js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#service").hover(function () {
            $(".service").show();
        }, function () {
            $(".service").hide();
        });
        $("#shopcar").hover(function () {
            $("#shopcarlist").show();
        }, function () {
            $("#shopcarlist").hide();
        });

    })
</script>
<script type="text/javascript" src="js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="js/widget/nav.js"></script>

<!--header-->
<div id="account">
    <div class="py-container">
        <div class="yui3-g home">
            <!--左侧列表-->
            <div class="yui3-u-1-6 list">

                <div class="person-info">
                    <div class="person-photo"><img src="img/_/photo.png" alt=""></div>
                    <div class="person-account">
                        <span class="name">{{user.username}}</span>
                        <span class="safe"><a href="#" @click="logout">退出登录</a></span>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="list-items">
                    <dl>
                        <dt><i>·</i> 订单中心</dt>
                        <dd><a href="home-index.html" class="list-active">我的订单</a></dd>
                        <dd><a href="home-order-pay.html">待付款</a></dd>
                        <dd><a href="home-order-send.html">待发货</a></dd>
                        <dd><a href="home-order-receive.html">待收货</a></dd>
                        <dd><a href="home-order-evaluate.html">待评价</a></dd>
                    </dl>
                    <dl>
                        <dt><i>·</i> 我的中心</dt>
                        <dd><a href="home-person-collect.html">我的收藏</a></dd>
                        <dd><a href="home-person-footmark.html">我的足迹</a></dd>
                    </dl>
                    <dl>
                        <dt><i>·</i> 物流消息</dt>
                    </dl>
                    <dl>
                        <dt><i>·</i> 设置</dt>
                        <dd><a href="home-setting-info.html">个人信息</a></dd>
                        <dd><a href="home-setting-address.html">地址管理</a></dd>
                        <dd><a href="home-setting-safe.html">安全管理</a></dd>
                    </dl>
                </div>
            </div>
            <!--右侧主内容-->
            <div class="yui3-u-5-6 order-pay">
                <div class="body">
                    <div class="table-title">
                        <table class="sui-table  order-table">
                            <tr>
                                <thead>
                                <th width="35%">宝贝</th>
                                <th width="5%">单价</th>
                                <th width="5%">数量</th>
                                <th width="8%">商品操作</th>
                                <th width="10%">实付款</th>
                                <th width="10%">交易状态</th>
                                <th width="10%">交易操作</th>
                                </thead>
                            </tr>
                        </table>
                    </div>

                    <div class="order-detail">


                        <div class="orders">
                            <div class="choose-order">
                                <span class='input-append'>
                                    <input placeholder="请输入商品名称......" type='text' id='orderSearch' v-model='query.key' size="50"/>
                                    <button class='sui-btn btn-large btn-primary' type='button'>搜索</button>
                                </span>
                                <div class="sui-pagination pagination-large top-pages">

                                    <ul>
                                        <li class="prev">
                                            <a href="#" @click.prevent="prePage">上一页</a>
                                        </li>

                                        <li class="next"><a href="#" @click.prevent="nextPage">下一页</a></li>
                                    </ul>
                                </div>
                            </div>
                            <div v-for="(order,i) in orders" :key="i">
                                <!--order1-->
                                <div class="choose-title">
                                    <label>
                                        <span>{{formatDate(order.createTime)}}　订单编号：{{order.orderId}}  店铺：我爱我家  <a>和我联系</a></span>
                                    </label>
                                    <a class="sui-btn btn-info share-btn">分享</a>
                                </div>
                                <table class="sui-table table-bordered order-datatable">
                                    <tbody v-for="(item,j) in order.orderDetails" :key="j">
                                    <tr>
                                        <td width="35%">
                                            <div class="typographic">
                                                <img :src="item.image"/>
                                            </div>
                                            <div>
                                                <a href="#" class="block-text">{{item.title}}</a>
                                            </div>
                                            <div>
                                                规格：
                                                <span class="guige" v-for="(v,k) in JSON.parse(JSON.parse(item.ownSpec))" :key="k">
                                                        {{v}}
                                                </span>
                                            </div>
                                        </td>
                                        <td width="5%" class="center">
                                            <ul class="unstyled">
                                                <li class="o-price">¥8888.00</li>
                                                <li>¥{{formatPrice(item.price)}}</li>
                                            </ul>
                                        </td>
                                        <td width="5%" class="center">{{item.num}}</td>
                                        <td width="8%" class="center">

                                        </td>
                                        <td width="10%" class="center">
                                            <ul class="unstyled">
                                                <li>¥{{formatPrice(item.num * item.price)}}</li>
                                                <li>（含运费：￥0.00）</li>
                                            </ul>
                                        </td>
                                        <td width="10%" class="center">
                                            <ul class="unstyled">
                                                <li>等待卖家付款</li>
                                                <li><a href="home-orderDetail.html" class="btn">订单详情 </a></li>
                                            </ul>
                                        </td>
                                        <td width="10%" class="center">
                                            <ul class="unstyled">
                                                <!--<li><a href="#" class="sui-btn btn-info">立即付款</a></li>-->
                                                <li><a @click="delOrder(item,j)" href="javascrpt:void(0);">取消订单</a></li>
                                            </ul>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                            <!-- &lt;!&ndash;order2&ndash;&gt;
                             <div class="choose-title">
                                 <label data-toggle="checkbox" class="checkbox-pretty ">
                                        <input type="checkbox" checked="checked"><span>2017-02-11 11:59　订单编号：7867473872181848  店铺：哇哈哈 <a>和我联系</a></span>
                                  </label>
                                   <a class="sui-btn btn-info share-btn">分享</a>
                             </div>
                             <table class="sui-table table-bordered order-datatable">
                                 <tbody>
                                     <tr>
                                         <td width="35%">
                                             <div class="typographic"><img src="img/goods.png" />
                                                 <a href="#" class="block-text">包邮 正品玛姬儿压缩面膜无纺布纸膜100粒 送泡瓶面膜刷喷瓶 新款</a>
                                                 <span class="guige">规格：温泉喷雾150ml</span>
                                             </div>
                                         </td>
                                         <td width="5%" class="center">
                                             <ul class="unstyled">
                                                 <li class="o-price">¥599.00</li>
                                                 <li>¥299.00</li>
                                             </ul>
                                         </td>
                                         <td width="5%" class="center">1</td>
                                         <td width="8%" class="center">
                                             <ul class="unstyled">
                                                 <li>已发货</li>
                                                 <li><a>退货/退款</a></li>
                                             </ul>
                                         </td>
                                         <td width="10%" class="center" rowspan="2">
                                             <ul class="unstyled">
                                                 <li>¥299.00</li>
                                                 <li>（含运费：￥0.00）</li>
                                             </ul>
                                         </td>
                                         <td width="10%" class="center" rowspan="2">
                                             <ul class="unstyled">
                                                 <li>部分发货</li>
                                                 <li><a href="home-orderDetail.html" class="btn">订单详情 </a></li>
                                             </ul>
                                         </td>
                                         <td width="10%" class="center" rowspan="2">
                                             <ul class="unstyled">
                                                 <li>还剩4天23时</li>
                                                 <li><a href="#" class="sui-btn btn-info">确认发货</a></li>
                                             </ul>
                                         </td>
                                     </tr>
                                     <tr>
                                         <td width="35%">
                                             <div class="typographic"><img src="img/goods.png" />
                                                 <a href="#" class="block-text">包邮 正品玛姬儿压缩面膜无纺布纸膜100粒 送泡瓶面膜刷喷瓶 新款</a>
                                                 <span class="guige">规格：温泉喷雾150ml</span>
                                             </div>
                                         </td>
                                         <td width="5%" class="center">
                                             <ul class="unstyled">
                                                 <li class="o-price">¥199.00</li>
                                                 <li>¥212.00</li>
                                             </ul>
                                         </td>
                                         <td width="5%" class="center">1</td>
                                         <td width="8%" class="center">
                                             <ul class="unstyled">
                                                 <li>未发货</li>
                                                 <li><a>退货/退款</a></li>
                                             </ul>
                                         </td>


                             </tr>

                             </tbody>
                         </table>

                         &lt;!&ndash;order3&ndash;&gt;
                         <div class="choose-title">
                             <label data-toggle="checkbox" class="checkbox-pretty ">
                                 <input type="checkbox" checked="checked"><span>2017-02-11 11:59　订单编号：7867473872181848  店铺：哇哈哈 <a>和我联系</a></span>
                             </label>
                             <a class="sui-btn btn-info share-btn">分享</a>
                         </div>
                         <table class="sui-table table-bordered order-datatable">
                             <tbody>
                             <tr>
                                 <td width="35%">
                                     <div class="typographic"><img src="img/goods.png"/>
                                         <a href="#" class="block-text">包邮 正品玛姬儿压缩面膜无纺布纸膜100粒 送泡瓶面膜刷喷瓶 新款</a>
                                         <span class="guige">规格：温泉喷雾150ml</span>
                                     </div>
                                 </td>
                                 <td width="5%" class="center">
                                     <ul class="unstyled">
                                         <li class="o-price">¥599.00</li>
                                         <li>¥299.00</li>
                                     </ul>
                                 </td>
                                 <td width="5%" class="center">1</td>
                                 <td width="8%" class="center">
                                     <ul class="unstyled">

                                         <li><a>退货/退款</a></li>
                                     </ul>
                                 </td>
                                 <td width="10%" class="center">
                                     <ul class="unstyled">
                                         <li>¥299.00</li>
                                         <li>（含运费：￥0.00）</li>
                                     </ul>
                                 </td>
                                 <td width="10%" class="center">
                                     <ul class="unstyled">
                                         <li>买家已付款</li>
                                         <li><a href="home-orderDetail.html" class="btn">订单详情 </a></li>
                                     </ul>
                                 </td>
                                 <td width="10%" class="center">
                                     <ul class="unstyled">
                                         <li><a href="#" class="sui-btn btn-info">提醒发货</a></li>
                                     </ul>
                                 </td>
                             </tr>


                             </tbody>
                         </table>-->


                        </div>
                        <div class="choose-order">
                            <div class="sui-pagination pagination-large top-pages">
                                <ul>
                                    <li class="{prev:true,disabled:search.page === 1}">
                                        <a href="#" @click.prevent="prePage">«上一页</a>
                                    </li>
                                    <li :class="{active: index(i) === query.page}" v-for="i in Math.min(5,totalPage)" :key="i">
                                        <a href="#" @click="query.page = index(i)">{{index(i)}}</a>
                                    </li>
                                    <li class="dotted"><span>...</span></li>
                                    <li class="{next:true,disabled:search.page === totalPage}">
                                        <a href="#" @click.prevent="nextPage">下一页»</a>
                                    </li>
                                </ul>
                                <div>
                                    <span>共{{totalPage}}页&nbsp;</span>
                                    <span>
                                        到<input type="text" class="page-num">页
                                    </span>
                                    <button class="page-confirm" @click="watchInput">确定</button>
                                </div>
                            </div>
                        </div>

                        <div class="clearfix"></div>
                    </div>

                    <div class="like-title">
                        <div class="mt">
                            <span class="fl"><strong>热卖单品</strong></span>
                        </div>
                    </div>
                    <div class="like-list">
                        <ul class="yui3-g">
                            <li class="yui3-u-1-4">
                                <div class="list-wrap">
                                    <div class="p-img">
                                        <img src="img/_/itemlike01.png"/>
                                    </div>
                                    <div class="attr">
                                        <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                    </div>
                                    <div class="price">
                                        <strong>
                                            <em>¥</em>
                                            <i>3699.00</i>
                                        </strong>
                                    </div>
                                    <div class="commit">
                                        <i class="command">已有6人评价</i>
                                    </div>
                                </div>
                            </li>
                            <li class="yui3-u-1-4">
                                <div class="list-wrap">
                                    <div class="p-img">
                                        <img src="img/_/itemlike02.png"/>
                                    </div>
                                    <div class="attr">
                                        <em>Apple苹果iPhone 6s/6s Plus 16G 64G 128G</em>
                                    </div>
                                    <div class="price">
                                        <strong>
                                            <em>¥</em>
                                            <i>4388.00</i>
                                        </strong>
                                    </div>
                                    <div class="commit">
                                        <i class="command">已有700人评价</i>
                                    </div>
                                </div>
                            </li>
                            <li class="yui3-u-1-4">
                                <div class="list-wrap">
                                    <div class="p-img">
                                        <img src="img/_/itemlike03.png"/>
                                    </div>
                                    <div class="attr">
                                        <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                    </div>
                                    <div class="price">
                                        <strong>
                                            <em>¥</em>
                                            <i>4088.00</i>
                                        </strong>
                                    </div>
                                    <div class="commit">
                                        <i class="command">已有700人评价</i>
                                    </div>
                                </div>
                            </li>
                            <li class="yui3-u-1-4">
                                <div class="list-wrap">
                                    <div class="p-img">
                                        <img src="img/_/itemlike04.png"/>
                                    </div>
                                    <div class="attr">
                                        <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                    </div>
                                    <div class="price">
                                        <strong>
                                            <em>¥</em>
                                            <i>4088.00</i>
                                        </strong>
                                    </div>
                                    <div class="commit">
                                        <i class="command">已有700人评价</i>
                                    </div>
                                </div>
                            </li>

                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 底部栏位 -->
<!--页面底部，由js动态加载-->
<div class="clearfix footer"></div>
<script type="text/javascript">$(".footer").load("foot.html");</script>

<script src="./js/axios.min.js"></script>
<script src="./js/common.js"></script>
<script src="./js/plugins/jquery/jquery.cookie.js"></script>
<!--页面底部END-->
</body>

<script type="text/javascript">
    var vm = new Vue({
        el: "#account",
        data: {
            ly,
            user: {},
            orders: [],
            query: {
                status: 0,
                page: 1,
                rows: 5,
                key:'',//搜索的字段
            },
            total: 0,//总条数，默认为0
            totalPage: 0,//总页数，默认为0
        },
        created() {
            ly.verifyUser()
                .then(resp => {
                    this.user = resp.data;
                    this.loadOrder();
                })
                .catch(() => {
                    this.gotoLogin();
                });
            this.query.key = this.getUrlParam("key");
        },
        methods: {

            logout() {
                // 删除cookie中的token即可
                ly.http.post("/auth/logOut")
                    .then(window.location.href="http://www.leyou.com"); //跳转到首页
            },

            gotoLogin() {
                window.location = "login.html?returnUrl=" + window.location;
            },
            loadOrder() {
                // 分页查询订单信息
                ly.http.get("/order/order/list?" + ly.stringify(this.query))
                    .then(({data: {items, total}}) => {
                        this.orders = items;
                        this.total = total;
                        this.totalPage = Math.ceil(total / this.query.rows);
                    })
                    .catch(() => this.orders = [])
            },
            formatDate: ly.formatDate,
            formatPrice: ly.formatPrice,
            getTotalPrice(order) {
                return order.orderDetails.map(d => d.num * d.price).reduce((v1, v2) => v1 + v2, 0);
            },
            prePage() {
                if (this.query.page > 1) {
                    this.query.page--;
                }
            },
            nextPage() {
                if (this.query.page < this.totalPage) {
                    this.query.page++;
                }
            },
            index(i) {
                if (this.query.page <= 3 || this.totalPage <= 5) {
                    // 当前页小于3，则页码就是从 i 开始
                    return i;
                } else if (this.query.page <= this.totalPage - 2) {
                    // 大于3，则从page-2开始，然后逐个加1
                    return this.query.page - 3 + i;
                } else {
                    return this.totalPage - 5 + i;
                }
            },
            watchInput() {
                //通过js的方式取出输入框里的值
                let num = document.getElementsByClassName("page-num")[0].value;
                this.query.page = num;
            },

            //取消订单
            delOrder(item,index) {
                ly.http.delete("order/order/del/"+item.title)
                    .then(() =>{
                        this.orders.splice(index,1);
                        alert("取消订单成功！")
                    })
            }
        },
        watch: {
            'query': {
                deep: true,
                handler() {
                    this.loadOrder();
                }
            }
        }
    });
</script>
</html>